// pages/my/finishOrder/finishOrder.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderData:null,
    orderId:null,
    appointmentId:null,
    typeList:'',
    money: 0,
    compare: app.globalData.min_money,
    isShowCode:false,
    codeImg:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let _this = this;
    app.util.ajax({
      url:"api/order/orderDetail",
      data:{
        order_id:options.orderId,
      }
    },function(data){
      let allData = data.data.data,
          serverType = '';
      for(var k of allData.items){
        serverType += k + ' '
      }
      _this.setData({
        orderData:allData,
        orderId:allData.order_id,
        appointmentId:allData.order_appointment.appointment_id,
        typeList:serverType
      })
    });
    
  },
  concat() {
    let _this = this;
    app.getBalance(function(money){
      app.util.ajax({
        url:'api/Appointment/contact',
        data:{
          id:_this.data.appointmentId
        }
      },function(res){
        let min_money = Number(res.data.data.limit_money),
            user_money = Number(money);
        if (money >= min_money) {
          _this.setData({
            isShowCode:true,
            codeImg:res.data.data.qrcode
          })
        }else{
          app.showServiceTips(min_money)
        }
      })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  
  // 跳转评价
  jumpEvaluate:function(){
    let appointmentId = this.data.appointmentId,
        orderId = this.data.orderId,
        str = 'appointmentId='+appointmentId+'&orderId='+orderId;
    app.util.pageJump('/pages/my/star/star?'+str);
  },
  // 立即支付
  atoncePayment:function(e){
    let index = e.currentTarget.dataset.index,
        _this = this,
        orderId = this.data.orderData.order_id,
        orderSn = this.data.orderData.order_sn,
        orderPrice = this.data.orderData.service_amount;
    app.util.pageJump('/pages/index/detail/placeOrder/paymentPassword/paymentPassword?order_id='+orderId+'&order_sn='+orderSn+'&price='+orderPrice);
  }
})